import  unittest

from parameterized import parameterized

from base import log
from page.page_app_login import PageAppLogin
from page.page_app_order import PageAppOrder
from util import GetDriver, read_json


class TestLogin(unittest.TestCase):
    def setUp(self):
        self.driver = GetDriver.get_app_driver()
        #获取登录实例
        self.app = PageAppLogin(self.driver)
        #获取下单实例
        self.order = PageAppOrder(self.driver)

    def tearDown(self):
        self.driver.quit()

    @parameterized.expand(read_json("app_order.json", "order"))
    def test01_app_login_order(self,vlaue,except_nickname):
        try:
            self.app.page_app_login()
            nickname = self.app.page_app_get_nickname()
            print("登录的昵称为：",nickname)
            self.assertEqual(except_nickname,nickname)
            #下单
            self.order.page_app_order(vlaue)
            ordernumber = self.order.page_app_get_ordernumber()
            print("获取的订单号为：",ordernumber)
        except Exception as e:
            # print("错误原因：",e)
            log.eror(e)
            #截图
            self.order.base_img()
            #抛异常
            raise
